package server.communication.ClientMessages;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import server.communication.Client;
import server.communication.MessageProcessor;

public class ExecuteBashCommandMessageThread extends ClientMessageThread{

	private String command;
	private PrintWriter rootOut;
	public ExecuteBashCommandMessageThread(Client parent, Socket root, String command) throws Exception
	{
		super(parent);
		this.command = command;
		rootOut = new PrintWriter(root.getOutputStream(), true);
	}
	
	@Override
	public void run()
	{
		String input = null;
		out.println(MessageProcessor.executeBashCommandRequest(command));
		while (true){
			try
			{
				input = in.readLine();
				if (input.startsWith("bash:"))
				{
					rootOut.println(input);
					break;
				}
				else
					parent.getMessageProcessor().process(input);
			}
			catch (Exception e ){rootOut.println( "done:exception");}
		}
		parent.removeMessageThread(this);
		parent.resumeMessages();
	}
}
